# encoding: utf-8
import time
import unittest
import threading
import selenium.webdriver.support.ui as ui
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
# from pykeyboard import PyKeyboard
import pymysql
import random


class IwebshopLoginTest(unittest.TestCase):
    def setUp(self):
        # self.driver = webdriver.Firefox()
        self.driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.CHROME)
        self.chrome_options = webdriver.ChromeOptions()
        self.chrome_options.add_argument('--no-sandbox')
        # self.driver = webdriver.Chrome()
        self.username = ""
        self.password = ""
        self.asserSuccess = ""
        self.mLoginKey = []
        self.driver.maximize_window()
        self.driver.implicitly_wait(30)
        print("setup")

    def tearDown(self):
        self.driver.quit()
        print("teardown")

    def test_merchant_login(self):
        self.driver.get("http://42.193.131.89/dist/#/mlogin")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
        self.driver.find_element(By.ID, "area").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("Ca11MeWZF!")
        self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
        self.username = self.driver.find_element_by_class_name("user-info-name")
        print(self.username)
        time.sleep(3)

    # def test_mercahnt_allkinds_login(self):
    #     self.mLoginKey = ["wzf:Ca11MeWZF!:yes", "a:a:yes", "Ca11MeWZF!:wzf:no", "wzf:Ca11MeWZF:no", "wzf:ca11mewzf!:no",
    #                       "WZF:CA11MeWZF!:no", "WZF:Ca11MeWZF!:no", " : :no", "::no", "wzf:wzf:no", "wzf::no",
    #                       "wzf:￥%*#:no", "!@#$:CA11MeWZF!:no",
    #                       "你好:Ca11MeWZF!:no", "wzf:哈哈:no"]
    #     self.driver.get("http://42.193.131.89/dist/#/mlogin")
    #     self.driver.implicitly_wait(2)
    #     for i in self.mLoginKey:
    #         Key = i.split(":")
    #         print("用户名:" + Key[0] + ",密码:" + Key[1] + ",是否登录成功断言:" + Key[2])
    #         self.username = Key[0]
    #         self.password = Key[1]
    #         nameInput = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner")
    #         nameInput.click()
    #         nameInput.send_keys(Keys.CONTROL, 'a')
    #         nameInput.send_keys(Keys.BACK_SPACE)
    #         nameInput.send_keys(Key[0])
    #         passwInput = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner")
    #         passwInput.click()
    #         passwInput.send_keys(Keys.CONTROL, 'a')
    #         passwInput.send_keys(Keys.BACK_SPACE)
    #         passwInput.send_keys(Key[1])
    #         element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary")
    #         actions = ActionChains(self.driver)
    #         actions.move_to_element(element).perform()
    #         self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
    #         time.sleep(2)
    #         try:
    #             element = self.driver.find_element(By.CSS_SELECTOR, ".el-icon-bell")
    #             actions = ActionChains(self.driver)
    #             actions.move_to_element(element).perform()
    #             element = self.driver.find_element(By.CSS_SELECTOR, "body")
    #             actions = ActionChains(self.driver)
    #             actions.move_to_element(element).perform()
    #             self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-link").click()
    #             self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-menu__item--divided").click()
    #             time.sleep(1)
    #             self.asserSuccess = "yes"
    #         except Exception as e:
    #             # js = "window.alert('用户名和密码输入有误')"
    #             # self.driver.execute_script(js)
    #             print("用户名和密码错误", e)
    #             self.asserSuccess = "no"
    #         try:
    #             self.assertEqual(self.asserSuccess, Key[2])
    #         except Exception as e:
    #             print("用户名：" + Key[0] + ",密码：" + Key[1] + "，断言为：" + Key[2] + ",断言错误")
    #             self.driver.get_screenshot_as_file("./images/%s.png" % str(self.username + self.password + "登录预测错误"))
    #             raise

    def test_admini_loginAndSeeAll(self):
        self.driver.get("http://42.193.131.89/dist/#/adminlogin")
        self.driver.set_window_size(1382, 744)
        self.driver.find_element(By.NAME, "username").click()
        self.driver.find_element(By.NAME, "username").send_keys("wzf")
        self.driver.find_element(By.NAME, "password").send_keys("Ca11MeWZF!")
        self.driver.find_element(By.CSS_SELECTOR, ".el-button").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-button")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(2)").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(3) > span").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(4) > span").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(5) > span").click()
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(6) > span").click()
        time.sleep(1)

    # def test_upload_product(self):
    #     self.driver.get("http://42.193.131.89/dist/#/mlogin")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("Ca11MeWZF!")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-submenu__title > span").click()
    #     time.sleep(3)
    #     self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/ul/li[3]/ul/li[1]').click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("手机")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-textarea__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-textarea__inner").send_keys("荣耀30s")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("手机")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-textarea__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.execute_script("window.scrollTo(0,0)")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("手机荣耀30s")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(5) .el-textarea__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(5) .el-textarea__inner").send_keys("商家付运费")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-icon-coin").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(2) > .el-input > .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(2) > .el-input > .el-input__inner").send_keys(
    #         "100")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(6) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(6) .el-input__inner").send_keys("2000")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(8) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(8) .el-input__inner").send_keys("100")
    #
    #     kk = PyKeyboard()
    #     self.driver.find_element_by_css_selector(
    #         '#app > div > div.content-box > div.content > div:nth-child(1) > div.container > div.form-box > form > div:nth-child(4) > div > div:nth-child(1) > div').click()
    #     time.sleep(1)
    #     kk.tap_key(kk.shift_key)  # 切换为英文，看实际情况是否需要
    #     # sleep(1)
    #     kk.type_string('F:\\Destop\\picture')  # 打开文件所在目录，方便多个文件上传
    #     time.sleep(1)
    #     kk.tap_key(kk.enter_key)
    #     time.sleep(1)
    #     kk.type_string('car.jpg')  # 多文件上传
    #     time.sleep(1)
    #     kk.tap_key(kk.enter_key)
    #     # self.driver.find_element_by_css_selector('#app > div > div.content-box > div.content > div:nth-child(1) > div.container > div.form-box > form > div:nth-child(4) > div > div:nth-child(1) > div').send_keys("F:\\Destop\\picture\\car.jpg")
    #     time.sleep(2)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item__content > .el-button--primary").click()
    #     time.sleep(3)

    def test_merchant_see_products(self):
        self.driver.get("http://42.193.131.89/dist/#/mlogin")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("Ca11MeWZF!")
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, ".el-submenu__title").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu--inline > .el-menu-item:nth-child(2)").click()
        self.driver.execute_script("window.scrollTo(0,0)")
        element = self.driver.find_element(By.CSS_SELECTOR, ".content")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).click_and_hold().perform()
        element = self.driver.find_element(By.CSS_SELECTOR, ".content")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        element = self.driver.find_element(By.CSS_SELECTOR, ".content")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).release().perform()
        time.sleep(3)

    def test_upload_share_product(self):
        self.driver.get("http://42.193.131.89/dist/#/mlogin")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("Ca11MeWZF!")
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
        time.sleep(1)
        element = self.driver.find_element(By.CSS_SELECTOR, "body")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-submenu__title > span").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu-item:nth-child(3)").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item__content > .el-input > .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item__content > .el-input > .el-input__inner").send_keys(
            "共享电瓶车")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-textarea__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-textarea__inner").send_keys("无押金")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input-number__increase")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-slider").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase")
        actions = ActionChains(self.driver)
        actions.double_click(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(4) .el-input-number__increase").click()
        self.driver.execute_script("window.scrollTo(0,0)")
        self.driver.find_element(By.CSS_SELECTOR, ".el-switch__core").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(6) .el-textarea__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(6) .el-textarea__inner").send_keys(
            "只能在金华市内使用")
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(2) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(2) .el-input__inner").send_keys("10")
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(4) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(4) .el-input__inner").send_keys("2")
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(6) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-col:nth-child(6) .el-input__inner").send_keys("1000")
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item__content > .el-button--primary").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-menu--inline > .el-menu-item:nth-child(4)").click()
        time.sleep(3)

    # def test_user_login(self):
    #     self.driver.get("http://42.193.131.89/dist/#/")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-notification__closeBtn").click()
    #     time.sleep(1)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-selfdefine").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-link--inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("Ca11MeWZF!")
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
    #     time.sleep(3)

    def test_search(self):
        content = ["honour phone:yes", "phone:yes", "PHONE:yes", " 计算机网络:yes", " 计算机网络 :yes", "计算机网络:yes", "网络 :yes",
                   "网络:yes", "  :yes", ":yes", "书:yes", "商家包邮:yes"]
        right = ""
        self.driver.get("http://42.193.131.89/dist/")
        for i in content:
            data = i.split(":")
            self.driver.find_element(By.CSS_SELECTOR, ".el-input__inner").click()
            self.driver.find_element(By.CSS_SELECTOR, ".el-input__inner").send_keys(data[0])
            self.driver.find_element(By.CSS_SELECTOR, ".el-button").click()
            time.sleep(1)
            try:
                # self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/div/div[2]/table/tbody/tr')
                self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/div/div[2]/table/tbody/tr[1]')
                right = "yes"
            except:
                right = "no"
            try:
                self.assertEqual(right, data[1])
            except Exception as e:
                self.driver.get_screenshot_as_file("./images/%s.png" % str(data[0] + "搜索预测错误"))
                raise
            self.driver.back()

    # def test_buy_product(self):
    #     self.driver.get("http://42.193.131.89/dist/#/")
    #     time.sleep(3)
    #     element = self.driver.find_element(By.CSS_SELECTOR, '.el-dropdown-selfdefine')
    #     webdriver.ActionChains(self.driver).move_to_element(element).click(element).perform()
    #     # self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-selfdefine").click()
    #     self.driver.implicitly_wait(30)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-link--inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-input--suffix > .el-input__inner").send_keys("Ca11MeWZF!")
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span").click()
    #     self.driver.execute_script("window.scrollTo(0,382)")
    #     time.sleep(3)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(1) > .el-table_2_column_5 img").click()
    #     # self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[7]/div/div[2]/table/tbody/tr[1]/td[1]/div/div[1]/img').click()
    #     time.sleep(1)
    #     self.driver.implicitly_wait(20)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--danger > span").click()
    #     self.driver.find_element(By.CSS_SELECTOR,
    #                              '#app > div > section > main > div.grid-content.bg-purple > div > div:nth-child(2) > button > span').click()
    #     # self.driver.find_element(By.XPATH,'//*[@id="app"]/div/section/main/div[7]/div/div[2]/button/span').click()
    #     time.sleep(1)
    #     print(self.driver.window_handles)
    #     vars = self.driver.window_handles
    #     # time.sleep(2)
    #     time.sleep(1)
    #     self.driver.switch_to.window(vars[1])
    #     self.driver.implicitly_wait(2)
    #     try:
    #         self.driver.find_element(By.LINK_TEXT, "< 登录账户付款").click()
    #     except Exception as e:
    #         pass
    #     self.driver.implicitly_wait(30)
    #     self.driver.find_element(By.ID, "J_tLoginId").click()
    #     self.driver.find_element(By.ID, "J_tLoginId").send_keys("mrsage5285@sandbox.com")
    #     time.sleep(1)
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").click()
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").send_keys("111111")
    #     time.sleep(1)
    #     self.driver.find_element(By.XPATH, '//*[@id="J_newBtn"]/span').click()
    #     self.driver.find_element(By.ID, "payPassword_rsainput").send_keys("111111")
    #     self.driver.find_element(By.ID, "J_authSubmit").click()
    #     time.sleep(7)

    # def test_rent_product(self):
    #     self.driver.get("http://42.193.131.89/dist/#/")
    #     time.sleep(3)
    #     # element = self.driver.find_element(By.CSS_SELECTOR, '.el-dropdown-selfdefine')
    #     # webdriver.ActionChains(self.driver).move_to_element(element).click(element).perform()
    # 
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-selfdefine")
    #     webdriver.ActionChains(self.driver).move_to_element(element).click(element).perform()
    #     # self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-selfdefine").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-link--inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-input--suffix > .el-input__inner").send_keys("Ca11MeWZF!")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
    #     time.sleep(1)
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(1) > .el-table_2_column_5 img").click()
    #     # self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_2_column_8 img").click()
    #     # self.vars["window_handles"] = self.driver.window_handles
    #     time.sleep(1)
    #     # self.driver.find_element(By.XPATH, '//*[@id="app"]/div/section/main/div[6]/div[2]/div/div/span[2]').click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--danger > span").click()
    #     # self.driver.find_element(By.XPATH, '//*[@id="app"]/div/section/main/div[7]/div/div[1]/button/span').click()
    #     time.sleep(1)
    #     print(self.driver.window_handles)
    #     # self.vars["win1042"] = self.wait_for_window(2000)
    #     # var = self.wait_for_window(2000)
    #     vars = self.driver.window_handles
    #     # time.sleep(2)
    #     time.sleep(2)
    #     self.driver.implicitly_wait(20)
    #     self.driver.switch_to.window(vars[1])
    #     self.driver.implicitly_wait(2)
    #     try:
    #         self.driver.find_element(By.LINK_TEXT, "< 登录账户付款").click()
    #     except Exception as e:
    #         pass
    #     self.driver.implicitly_wait(30)
    #     self.driver.find_element(By.ID, "J_tLoginId").click()
    #     self.driver.find_element(By.ID, "J_tLoginId").send_keys("mrsage5285@sandbox.com")
    #     time.sleep(1)
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").click()
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").send_keys("111111")
    #     time.sleep(1)
    #     self.driver.find_element(By.XPATH, '//*[@id="J_newBtn"]/span').click()
    #     # try:
    #     #     self.driver.find_element(By.CSS_SELECTOR, "span:nth-child(7)").click()
    #     # except Exception as e:
    #     #     pass
    #     self.driver.implicitly_wait(20)
    #     self.driver.find_element(By.ID, "payPassword_rsainput").send_keys("111111")
    #     self.driver.find_element(By.ID, "J_authSubmit").click()
    #     time.sleep(7)

    def test_share_mode(self):
        self.driver.get("http://42.193.131.89/dist/#/shareProduct?id=94221581122912800")
        self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(6) > span").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
        self.driver.find_element(By.CSS_SELECTOR, ".el-input--suffix > .el-input__inner").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-input--suffix > .el-input__inner").send_keys("Ca11MeWZF!")
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span").click()
        self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(4) > span").click()
        element = self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(5) > span")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        element = self.driver.find_element(By.CSS_SELECTOR, "body")
        actions = ActionChains(self.driver)
        actions.move_to_element(element).perform()
        self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(5)").click()
        time.sleep(2)

    # def test_share_mode(self):
    #     self.driver.get("http://42.193.131.89/dist/#/shareProduct?id=94221581122912800")
    #     self.driver.implicitly_wait(20)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(4) > span").click()
    #     self.driver.implicitly_wait(20)
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(5) > span")
    #     time.sleep(3)
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.implicitly_wait(20)
    #     element = self.driver.find_element(By.CSS_SELECTOR, "body")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.implicitly_wait(20)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(5) > span").click()
    #     self.driver.implicitly_wait(20)
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button:nth-child(4) > span")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.implicitly_wait(20)
    #     element = self.driver.find_element(By.CSS_SELECTOR, "body")
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     time.sleep(5)
    #     vars = self.driver.window_handles
    #     # time.sleep(2)
    #     time.sleep(1)
    #     self.driver.switch_to.window(vars[1])
    #     self.driver.implicitly_wait(20)
    #     try:
    #         self.driver.find_element(By.LINK_TEXT, "< 登录账户付款").click()
    #     except Exception as e:
    #         pass
    #     self.driver.implicitly_wait(30)
    #     self.driver.find_element(By.ID, "J_tLoginId").click()
    #     self.driver.find_element(By.ID, "J_tLoginId").send_keys("mrsage5285@sandbox.com")
    #     time.sleep(1)
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").click()
    #     self.driver.find_element(By.ID, "payPasswd_rsainput").send_keys("111111")
    #     time.sleep(1)
    #     self.driver.find_element(By.XPATH, '//*[@id="J_newBtn"]/span').click()
    #     # try:
    #     #     self.driver.find_element(By.CSS_SELECTOR, "span:nth-child(7)").click()
    #     # except Exception as e:
    #     #     pass
    #     self.driver.find_element(By.ID, "payPassword_rsainput").send_keys("111111")
    #     self.driver.find_element(By.ID, "J_authSubmit").click()
    #     time.sleep(7)

    # def test_refund(self):
    #     self.driver.get("http://42.193.131.89/dist/#")
    #     time.sleep(3)
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-dropdown-selfdefine").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-link--inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").click()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-input--suffix > .el-input__inner").send_keys("Ca11MeWZF!")
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("wzf")
    #     element = self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span")
    #     time.sleep(3)
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary > span").click()
    # 
    #     self.driver.find_element(By.CSS_SELECTOR, "#app > div > ul > li:nth-child(9) > div").click()
    #     print(self.driver.window_handles)
    #     # self.driver.find_element(By.CSS_SELECTOR, ".is-opened .el-submenu__icon-arrow").click()
    #     # self.driver.find_element(By.CSS_SELECTOR,
    #     #                          ".el-menu--horizontal:nth-child(6) .el-menu-item:nth-child(1)").click()
    #     element = self.driver.find_element(By.XPATH, '/html/body/div[2]/ul/li[1]')
    #     actions = ActionChains(self.driver)
    #     actions.move_to_element(element).perform()
    #     element.click()
    #     self.driver.find_element(By.CSS_SELECTOR,
    #                              ".el-table__row:nth-child(1) > .el-table_3_column_16 .el-button:nth-child(1) > span").click()
    #     time.sleep(2)
    #     self.driver.refresh()
    #     time.sleep(3)

    def test_see_product_details(self):
        pids = []
        specialIds = ["", "0" * 16, "9" * 16, "!" * 16, "我" * 16, "a" * 16, "0" * 17, "9" * 17]
        # 连接数据库，得到全部审核通过的产品的id，放进pids这个列表中
        try:
            conn = pymysql.connect(host='1.15.133.55', user="tester", password="tester",
                                   database="sharedlease")
            print("数据库连接成功")
        except pymysql.Error as e:
            print("数据库连接失败：" + str(e))
        cur = conn.cursor()
        cur.execute("select * from product where legal=1;")
        while 1:
            res = cur.fetchone()
            if res is None:
                # 表示已经取完结果集
                break
            # res[0]就是产品id
            pids.append(res[0])
        cur.close()
        # conn.commit()
        conn.close()

        # 遍历pids，按理来说这里的产品id都能加载出产品图片来
        for pid in pids:
            self.driver.get("http://42.193.131.89/dist/#/production?id=" + str(pid))
            time.sleep(1)
            self.driver.refresh()
            self.driver.implicitly_wait(30)
            # time.sleep(5)
            try:
                self.driver.find_element(By.CSS_SELECTOR,
                                         "#app > div > section > aside > div > div.el-scrollbar__wrap > div > div > div > img")
            except:
                # try里查找元素找不到说明图片加载不出来
                print("数据库中id为" + str(pid) + "的产品图片没加载出来，跟预期不符")
                raise
        print("存在于数据库中的产品id都能访问到产品图片，测试通过！！！")

        # 随机生成id，如果该id不存在于pids中，按理应该访问不到产品图片
        for i in range(5):
            randomId = random.randint(1000000000000000, 9999999999999999)
            if randomId not in pids:
                self.driver.implicitly_wait(30)
                print("随机生成的" + str(randomId) + "产品id不存在于数据库中，被用来做不存在的pid的测试")
                self.driver.get("http://42.193.131.89/dist/#/production?id=" + str(randomId))
                time.sleep(1)
                self.driver.refresh()
                time.sleep(3)
                # print(self.driver.window_handles)
                # self.driver.switch_to.window(self.driver.window_handles[1])
                self.driver.implicitly_wait(1)
                try:
                    self.driver.find_element(By.CSS_SELECTOR,
                                             "#app > div > div.error-desc")
                except:
                    print("数据库中不存在的产品id" + str(randomId) + "访问不到404页面，跟预期不符")
                    raise Exception("数据库中不存在的产品id" + str(randomId) + "访问不到404页面，跟预期不符")
        print("随机生成的不存在于数据库中的id都访问不到产品图片，测试通过！！！")

        # 特殊且不存在于数据库中产品id的测试，预期都访问404页面
        for id in specialIds:
            self.driver.implicitly_wait(30)
            self.driver.get("http://42.193.131.89/dist/#/production?id=" + str(id))
            time.sleep(1)
            self.driver.refresh()
            time.sleep(3)
            self.driver.implicitly_wait(1)
            try:
                self.driver.find_element(By.CSS_SELECTOR,
                                         "#app > div > div.error-desc")
            except:
                print("数据库中不存在的产品特殊pid" + str(id) + "访问不到404页面，跟预期不符")
                raise Exception("数据库中不存在的产品特殊pid" + str(id) + "访问不到404页面，跟预期不符")
        print("特殊且不存在于数据库中产品id的测试通过！！！")

        # 点点点的方式进行测试
        self.driver.get("http://42.193.131.89/dist/")
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_1_column_1 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(1) > .el-table_2_column_6 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(1) > .el-table_3_column_11 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(1) > .el-table_4_column_16 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_5_column_17 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_6_column_22 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_7_column_27 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(2) > .el-table_8_column_32 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, ".el-table__row:nth-child(3) > .el-table_9_column_33 img").click()
        self.driver.execute_script("window.scrollTo(0,9)")
        time.sleep(3)
        self.driver.back()
        print("点点点的方式查看多个产品细节，都能访问到产品图片，测试通过！！！")
